﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DingApi
{
    public partial class print_view : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!this.Page.IsPostBack)
            {

                GridView1.Visible = true;

                string sql_cols = "VEHICLE_NO, BILL_STATUS,    TOTAL_WT,TOTAL_NUM,REMARK";

                sql_cols = sql_cols + ", 'DB' || MOVE_STOCK_APPLY_NO  as  MOVE_STOCK_APPLY_NO ,to_char(to_date(APPLY_TIME,'yyyymmddhh24miss'),'hh24:mi')   OUT_STOCK_DATE ";



                string sql = " select " + sql_cols + " "
                            + " from (SELECT *  FROM  TMM0031 WHERE MOVE_STOCK_TYPE ='BC' and Branch_Code = 'N' order by APPLY_TIME desc)    "
                            + " where rownum <5 ";


                if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
                {
                    sql_cols = "VEHICLE_NO, BILL_STATUS,   TOTAL_WT,TOTAL_NUM,REMARK " 
                              + ",'XS' || OUT_STOCK_NO  MOVE_STOCK_APPLY_NO 	,OUT_STOCK_APPLY_NO,to_char(to_date(OUT_STOCK_DATE,'yyyymmddhh24miss'),'hh24:mi')   OUT_STOCK_DATE "
                              ;

                    sql = " select " + sql_cols + " "
                            + " from (SELECT *  FROM  TMM0022 WHERE OUT_STOCK_MODE='XC' and Branch_Code = 'N' and    REC_CREATE_TIME >'"+ DateTime.Now.ToString("yyyyMMdd") + "' order by REC_CREATE_TIME    desc)    "
                            + " where rownum <5 ";

                    Label_head.Text = "销售出库，仅查询最近的4条记录！";
                }
                 


                EI.EIInfo outBlock = EF.Utility.ExecQuery(sql);



                if (outBlock.sys_info.flag != 0)
                {
                    this.Labl_Note.Text = "错误:" + outBlock.sys_info.msg;
                    return;
                }

                if (outBlock.Tables[0].Rows.Count > 0)
                {

                    GridView1.DataSource = outBlock.Tables[0];
                    GridView1.DataBind();
                    this.Labl_Note.Text = "";
                }
                else
                {
                    GridView1.Visible = false;
                    this.Labl_Note.Text = "暂无数据";
                }

            }
        }

        protected override void Render(HtmlTextWriter writer)
        {



            foreach (GridViewRow gvr in this.GridView1.Rows)
            {
                foreach (TableCell cell in gvr.Cells)
                {
                    if (cell is DataControlFieldCell)
                    {
                        cell.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.GridView1,
                            String.Format("CommandGetRowCellIndex${0}:{1}", gvr.RowIndex, gvr.Cells.GetCellIndex(cell)), true);

                        // Button1.Attributes.Add("onclick", "javascript:return confirm('yes or no');");
                    }
                }
            }

            base.Render(writer);

            //Button1.Visible = true;
            //GridView_XS.Visible = true;
            //GridView1.Visible = false;
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#106CC3'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                e.Row.Attributes["style"] = "Cursor:hand";

                if (e.Row.RowIndex % 2 == 0)
                {
                    e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#E8E8E8");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E8E8E8'");//当鼠标移开时还原背景色 
                }
                else
                {
                    e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");//当鼠标移开时还原背景色 
                }

                //Label labValue = (Label)e.Row.FindControl("Lable_FOR_SEND_MAT_WT");
                //if ( labValue != null)
                //{

                //    if (decimal.Parse(labValue.Text) <= 0
                //   // &&e.Row.RowState!=DataControlRowState.Selected
                //    ) /*尚未解决，DataControlRowState.Selected 不是当前选中的记录，是先前选中的*/
                //    e.Row.BackColor = System.Drawing.Color.LightGray;

                //}

            }

        }

 
 






    }
}